

# class array(self,):
#     arr: list[int] = [0] * 5
#     nums: list[int] = [1, 3, 2, 4, 5]

#     def random_access(nums: list[int]) -> int:
#         '''随机访问元素'''
#         random_index = random.randint(0, len(nums) - 1)
#         random_num = nums[]

from collections import deque

class TreeNode:
    def __init__(self, val: int):
        self.val: int = val
        self.left = None
        self.right = None

    def level_order(root):
        '''层序遍历'''
        queue = deque()
        queue.append(root)
        res = []
        while queue:
            node = queue.popleft()
            res.append(node.val)
            if node.left is not None:
                queue.append(node.left)
            if node.right is not None:
                queue.append(node.right)
        return res




if __name__ == '__main__':
    # 初始化二叉树
    n1 = TreeNode(1)
    n2 = TreeNode(2)
    n3 = TreeNode(3)
    n4 = TreeNode(4)
    n5 = TreeNode(5)
    
    n1.left = n2
    n1.right = n3
    n2.left = n4
    n2.right = n5

    # 插入与删除结点
    p = TreeNode(0)
    n1.left = p
    p.left = n2
    n1.left = n2

    # 层序遍历
    res = TreeNode.level_order(n1)
    print("\n层序遍历的节点打印序列 = ", res)


    




